/*
 * Copyright (c) 2011 Jean-Marc Perronne
 * Ensisa, 12 rue des Freres Lumieres, F-68093 Mulhouse cedex
 * All rights reserved.
 *
 * The copyright of this software is owned by Werner Randelshofer. 
 * You may not use, copy or modify this software, except in  
 * accordance with the license agreement you entered into with  
 * Jean-Marc Perronne. For details see accompanying license terms. 
 */

package fr.uha.ensisa.jmp.drone.handler;

public abstract class Handler implements Runnable
{
	private volatile boolean active;	
	private volatile boolean running;	

	public Handler()
	{
		this.active = false;
		this.running = false;
	}
	
	public abstract void close();
	
	public synchronized void start()
	{
		this.active = true;
	}

	public synchronized void terminate()
	{
		this.active = false;
	}
	
	public synchronized boolean isActive()
	{
		return this.active;
	}

	public synchronized boolean isRunning()
	{
		return this.running;
	}
	
	public synchronized void running()
	{
		this.running = true;
	}
	
	public synchronized void notRrunning()
	{
		this.running = false;
	}

	
	public void shutdown()
	{
		while(this.running)
		{
			Thread.yield();
		}
		System.out.println (this.getClass().getName() + " is terminated");

		this.close();
	}
	
}
